Repository navigation
feat(payments): let clients see their subscription tier - #926
Priyanshubhartistm wants to merge 4 commits into
Conversation
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
🦋 Changeset detectedLatest commit: e34f566 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
[Medium impact] The PR adds public subscription details to two client-facing relay paths. Add CORS headers before merging so browser clients on other sites can use the new endpoint. Findings
|
Coverage Report for CI Build 40026647273Warning No base build found for commit Coverage: 75.627%Details
Uncovered Changes
Coverage RegressionsRequires a base build to compare against. How to fix this → Coverage Stats💛 - Coveralls |
…e not 32 bytes Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
| return raw | ||
| } | ||
|
|
||
| if (/^npub1/.test(raw)) { |
There was a problem hiding this comment.
A valid all-uppercase NPUB1... gets a 400 response because parsePubkey checks the prefix with a case-sensitive regex. Clients using this encoding cannot check their subscription, even though fromNpub already supports it. Make the prefix check case-insensitive and add an endpoint test for an uppercase npub.
| if (/^npub1/.test(raw)) { | |
| if (/^npub1/i.test(raw)) { |
|
@Priyanshubhartistm Let's please fix the issue flagged by Greptile |
| } | ||
| : { pubkey, planId: null, status: null, active: false, currentPeriodEnd: null, accessEndsAt: null } | ||
|
|
||
| response.status(200).setHeader('content-type', 'application/json; charset=utf8').send(body) |
There was a problem hiding this comment.
Browser clients cannot read subscriptions
/subscriptions/status returns no Access-Control-Allow-Origin header, and neither the app nor the router adds one. Browser clients hosted on another site therefore cannot read the response or show the user's subscription tier, even when the request succeeds. Add CORS headers to this public endpoint, including its error responses.
Description
Builds on the subscription lifecycle (#909). Nothing changes unless
payments.enabledis true andpayments.subscriptionPlansis non-empty.fees.subscription, one entry per plan withamountin msats,unit, andperiodin seconds (the standard NIP-11 shape), plusid, which is what a client sends asplanIdtoPOST /invoices, anddescriptionwhen the plan has one.limitation.restricted_writesis now true when plans are in use, since a subscription is what lets a pubkey write even without an admission fee.GET /subscriptions/status?pubkey=<hex or npub>returns the pubkey'splanId,status,active,currentPeriodEndandaccessEndsAt(ISO dates, null when it never ends).activeis judged from the dates, as the write gate does, so grace counts and a lapsed subscription the sweep has not reached yet does not. A pubkey with no subscription gets nulls andactive: false. It answers 400 for an invalid pubkey and 404 while plans are off, and is counted againstlimits.invoice.rateLimitsunder its own key.CONFIGURATION.mddescribes both.Related Issue
Closes #925
Motivation and Context
The endpoint is public, like
/admissions/check/:pubkey, and only reports what the relay already enforces for that pubkey.